<?php
namespace Home\Controller;
use Think\Controller;
class VideoController extends Controller {
     public function videolist(){//视频列表-赵明月

        $admin = M('clubadmin');
        $c_tel=$_SESSION['c_tel'];
        $admins=$admin->where("c_tel='$c_tel'")->find();
        $this->admin=$admins;
        $clubname=$admin->clubname;
        $clubs = M('club');
        $res = $clubs->where("club_name='$clubname'")->select();
         $vid=$res['0']['cid'];
        $videos = M('video');
        $res1 = $videos->where("cid='$vid'")->select();
        $this->qrcodeList=$res1;
         $qrcodenum=$videos->where("cid='$vid'")->count();
    $Page = new \Think\Page($qrcodenum,5);
    $Page->setConfig('header', '共<b>%TOTAL_ROW%</b>条记录&nbsp;&nbsp;
   每页<b>5</b>条&nbsp;&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页');
    $Page->setConfig('prev','上一页');
    $Page->setConfig('next','下一页');
    $Page->setConfig('last','末页');
    $Page->setConfig('first','首页');
    $Page->setConfig('theme',' %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
    $this->pageNav=$Page->show();//在页面{pageNav}
        //$this->link=$Page->show();
    $this->qrcodeList=$videos->where("cid='$vid'")->limit($Page->firstRow,5)->order('vid asc')->select();

        $this->display();

    }

public function delvideo($vid){//删除视频-赵明月
  
        $videosModel=M('video');
        $res=$videosModel->where("vid=$vid")->find();
        $photoPath = realpath("./Public/upload/videofile/".$res['video_file']);
        unlink($photoPath);
        //$res=$usersmodel->where("id=$id")->delete();
        if ($videosModel->delete($vid)) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败');
        }
    }
     public function addvideo(){
        $admin = M('clubadmin');
        $c_tel=$_SESSION['c_tel'];
        $admins=$admin->where("c_tel='$c_tel'")->find();
        $this->admin=$admins;
        $clubname=$admin->clubname;
        $clubs = M('club');
        $res = $clubs->where("club_name='$clubname'")->select();
        $teacher_id=$res['0']['cid'];
        //var_dump($coachid);
        /*$teachers = M('teacher');
        $res1 = $teachers->where("cid='$teacher_id'")->select();
        $this->list1=$res1;*/
        $this->display();

    }

 Public function dovideo(){//添加视频-赵明月
        $data=$_POST;
        $file=$_FILES;
        $videoModel = M('video'); // 实例化User模型
        $videoModel->video_name =  I('post.video_name'); // 设置用户的创建时间
        $videoModel->uploaddate =  date("Y-m-d H:i:s"); // 设置用户的创建时间
        if ($file['video_file']['size']==0) {//没有上传轮播图片
            //$this->error('请上传背景图片！');                         
        }else{//有图片
            $info=$this->MyUpload();
            $videoModel->video_file = $info['video_file']['savename']; // 保存上传的照片根据需要自行组装
        }
     /*   $addresult=$videoModel->add(); // 写入用户数据到数据库
        if (false !== $addresult){
            $this->success('添加视频成功！','videolist');
        }else{ 
            $this->error('数据错误'); 
        }*/


        $admin = M('clubadmin');
        $c_tel=$_SESSION['c_tel'];
        $admins=$admin->where("c_tel='$c_tel'")->find();
        $this->admin=$admins;
        $clubname=$admin->clubname;
        $clubs = M('club');
        $res = $clubs->where("club_name='$clubname'")->select();
        $cid=$res['0']['cid'];
        $videoModel->cid=$cid;
        if(false!=$videoModel->add()){
                $this->success('添加成功!',U('videolist'));
            }else{$this->error('数据错误');}
        
    }

     public function MyUpload(){//上传图片-赵明月
                //上传头像
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize  = 100000000000 ;// 设置附件上传大小
        //$upload->allowExts  = array('mp4','jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->exts  = array('jpg', 'gif', 'png', 'jpeg','mp4');
        $upload->rootPath  =  './';
        $upload->savePath =  'Public/upload/videofile/';// 设置附件上传目录

        $upload->autoSub = false;
        $upload->saveName = date("YmdHis").rand(100,999);//定义名字
        // 上传单个文件 
        $info = $upload->upload();                    
            if(!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{// 上传成功 获取上传文件信息
                return $info;
            }
    } 
}